def prost(x):
    k=0
    for d in range(1,X+1):
        if x%d == 0:
            k+=1
    if k==2:
        return True
    else:
        return False
first_num=0
second_num=0
num=''
s=input().split()
sp_chis=['zero','one','two','three','four','five','six','seven','eight','nine']
if len(s)!=3 or s[0]=='0':
    print('wrong input')
else:
    for i in s:
        if i in sp_chis:
            num+=str(sp_chis.index(i))
    for p in range(int(num)+1,1000):
        if prost(p)==True:
            first_num=p
            break
    for p in range(int(num)-1,0,-1):
        if prost(p)==True:
            second_num=p
            break
    if abs(int(num)-first_num)>= abs(int(num)-second_num):
        print(second_num)
    else:
        print(first_num)
    
